#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2

def compare_images(img1, img2):
    # 加载两张图片
    # img1 = cv2.imread(image1)
    # img2 = cv2.imread(image2)

    # 将图片转换为灰度图像
    gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
    gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

    # 计算图像的直方图
    hist1 = cv2.calcHist([gray1], [0], None, [256], [0, 256])
    hist2 = cv2.calcHist([gray2], [0], None, [256], [0, 256])

    # 使用巴氏距离计算相似度
    similarity = cv2.compareHist(hist1, hist2, cv2.HISTCMP_BHATTACHARYYA)

    return similarity

imgA_1 = cv2.imread("../img/A-1.jpg")
imgA_2 = cv2.imread("../img/A-2.jpg")
imgB_1 = cv2.imread("../img/B-1.jpg")
imgB_2 = cv2.imread("../img/B-2.jpg")
imgC_1 = cv2.imread("../img/C-1.jpg")
imgC_2 = cv2.imread("../img/C-2.jpg")
imgD_1 = cv2.imread("../img/D-1.jpg")
imgD_2 = cv2.imread("../img/D-2.jpg")
# 测试
# image1 = "../img/D-1.jpg"
# image2 = "../img/D-2.jpg"
# similarity_score = compare_images(image1, image2)#巴式距离
# print("Similarity score:", 1-similarity_score)

